/**
 * Created by Administrator on 2017/4/5.
 */
'use strict';
swan_pc.directive('oppElement',function ($rootScope,ngDialog) {
    return {
        templateUrl: 'scripts/services/directive/oppElement/oppElement.html',
        scope: {
            struct: '=',
            info: '=',
            list: '=',
            // disabled1: '@',
            // blockName: '@',
            // dirtySet:'&',
            // dirtyGet: '&',
        },
        controller: ['$scope', '$rootScope', function ($scope, $rootScope) {

            $scope.compare=function (data1, data2) {
                if (angular.equals(data1,data2)){
                    return true;
                }else {
                    if (angular.isObject(data1)&&angular.isObject(data2)){
                        return data1.id==data2.id;
                    }
                }
                return false;
            };
            $scope.compareByte=function (data1,data2) {
                if (data1==null||data2==null){
                    return false;
                }
                return data1&data2;
            };

            $scope.getList=function () {
                $scope.selected='';
                if($scope.struct.type==2){
                    angular.forEach($scope.struct.select,function (item) {
                        if($scope.compare(item.value,$scope.info)){
                            $scope.selected=item.name;
                        }
                    })
                }
                else if($scope.struct.type==3){
                    angular.forEach($scope.struct.select,function (item) {
                        if (item.value&$scope.info){
                            $scope.selected+=item.name;
                            $scope.selected+=item.value*2>$scope.info?'。':'、';
                        }
                    })
                }
            }
            $scope.getList();
        }]
    }
})